package com.penghe.www.httplibrary

/**
 * Created by pengh on 2017/5/29.
 * 执行请求的代理类
 */

class HttpHelper private constructor() : IHttpProcessor {
    companion object {
        private var mIIHttpProcessor: IHttpProcessor? = null
        private var _INSTANCE: HttpHelper? = null
        fun init(iHttpProcessor: IHttpProcessor) {
            mIIHttpProcessor = iHttpProcessor
        }

        fun obtain(): HttpHelper {
            if (_INSTANCE == null) {
                synchronized(HttpHelper::class) {
                    if (_INSTANCE == null) {
                        _INSTANCE = HttpHelper()
                    }
                }
            }
            return _INSTANCE!!
        }
    }

    override fun get(url: String, params: Map<String, Any>, callBack: ICallBack) {
        if (mIIHttpProcessor == null) {
            throw Exception("please init HttpHelper before use it")
        }
        mIIHttpProcessor!!.get(url, params, callBack)
    }

    override fun post(url: String, params: Map<String, Any>, callBack: ICallBack) {
        if (mIIHttpProcessor == null) {
            throw Exception("please init HttpHelper before use it")
        }
        mIIHttpProcessor!!.post(url, params, callBack)
    }

}